// 065959264	Limor Bagizada	040199770	Sarit Chicotay

package Base;

public class NGram implements Comparable<NGram>{
	
		private String word;
		private String condWord;
		int nGram;
		
		public NGram(String w, String cond_w){
			word = w;
			condWord = cond_w;
			
			if (cond_w == null || cond_w.trim().equals(""))
				nGram = 1; // unigram
			else
				nGram=2; // bigram
		}	
	
		/**
		 * @return the word
		 */
		public String getWord() {
			return word;
		}
	
		/**
		 * @return the givenWords
		 */
		public String getConditioningWord() {
			return condWord;
		}

		/**
		 * @return NGram
		 */
		public int getNGram()
		{
			return nGram;
		}	

		@Override
		public boolean equals(Object obj) {
			
			 if (this == obj)
		        return true;
			 
		    if (obj == null)
		        return false;
		    if (getClass() != obj.getClass())
		        return false;
		    NGram other = (NGram) obj;
		    if (other.getNGram() != this.getNGram())
		        return false;
		    if (!other.getWord().equals(this.getWord()))
		        return false;
		    if (!other.getConditioningWord().equals(this.getConditioningWord()))
		    	return false;
		    	
		    return true;
		}
		
		@Override
		public int compareTo(NGram o) {
			int val = this.getWord().compareTo(o.getWord());
			if (val == 0 && nGram > 1)
				 val = this.getConditioningWord().compareTo(o.getConditioningWord());
			
			return val;
		}

		@Override
		public String toString() {
			StringBuilder b = new StringBuilder(this.word);
			if (nGram > 1)
			{
				b.append("|");
				b.append(this.condWord);
			}
			return b.toString();
		}
		
		

	
}
